package com.example.aliceapp;

import java.util.Stack;

public class StorageStack {

	private Stack<StorageVO> commandStack;
	
	public StorageStack(){
		commandStack = new Stack<StorageStack.StorageVO>();
	}
	
	public void clear(){
		commandStack.clear();
	}
	
	public void putCommand(char cmd){
		char inverseCMD = getInverse(cmd);
		commandStack.push(new StorageVO(inverseCMD, System.nanoTime()));
	}
	
	public StorageVO getNextCommand(){
		return commandStack.pop();
	}
	
	public boolean isEmpty(){
		return commandStack.isEmpty();
	}
	
	public StorageVO peek(){
		return commandStack.peek();
	}
	
	private char getInverse(char cmd) {
		if(cmd == '7'){
			cmd = '8';
		}else if(cmd == '8'){
			cmd = '7';
		}else if(cmd == '9'){
			cmd = ':';
		}else if(cmd == ':'){
			cmd = '9';
		}else if(cmd == ';'){
			cmd = '=';
		}else if(cmd == '<'){
			cmd = '>';
		}else if(cmd == '='){
			cmd = ';';
		}else if(cmd == '>'){
			cmd = '<';
		}
		return cmd;
	}

	public class StorageVO{
		private char command;
		private long time;
		
		public StorageVO(char cmd, long time){
			this.setCommand(cmd);
			this.setTime(time);
		}

		public char getCommand() {
			return command;
		}

		public void setCommand(char command) {
			this.command = command;
		}

		public long getTime() {
			return time;
		}

		public void setTime(long time) {
			this.time = time;
		}
	}
}
